import React, { Component } from 'react';
import '../styles/Login.scss'
import { user_login } from "../api/index";

class Login extends Component {
  constructor(props) {
    super(props)
    this.state = {
      phone: '', pass: ''
    }
  }
  tongbu(e) {
    this.setState({ [e.target.name]: e.target.value })
  }
  async login() {
    var res = await user_login(this.state)
    localStorage.setItem('token', res.data.token)
    console.log(res.data);
  }
  render() {
    return (
      <div className='login'>
        <h3>登录</h3>
        <div className="box">
          <input type="text" name='phone' placeholder='请输入用户名' value={this.state.phone} onChange={(e) => { this.tongbu(e) }} />
        </div>
        <div className="box">
          <input type="password" name='pass' placeholder='请输入密码' value={this.state.pass} onChange={(e) => { this.tongbu(e) }} />
        </div>

        <div className="box">
          <input type="button" value='登录' onClick={() => { this.login() }} />
        </div>
        <p>去注册</p>
      </div>
    );
  }
}

export default Login;